/**
 * Date Util
 */
class DateUtil {
  /**
   * get date pre 24 hours
   * @return {Date}
   */
  static getDatePre24H() {
    const interval = 24 * 60 * 60 * 1000;
    return new Date(Date.now() - interval);
  }

  /**
   * get today date with start time
   * @return {Date}
   */
  static today() {
    const date = new Date();
    date.setHours(0, 0, 0, 0);
    return date;
  }

  /**
   * checkCurrentRange
   * @param {Integer} time
   * @param {Integer} minutes
   * @return {Boolean/Array}
   */
  static checkCurrentRange(time, minutes) {
    const interval = minutes * 60 * 1000;

    const now = Date.now();
    const overNow = now % interval;
    const startTime = now - overNow;
    const endTime = now + interval;
    const overTime = time % interval;

    if (time - overTime >= startTime) {
      return [startTime, endTime];
    } else {
      return false;
    }
  }
}

module.exports = DateUtil;
